import {createRouter, createWebHistory} from 'vue-router'

import Layout from '@/views/Layout/index.vue'
import Login from '@/views/Login/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList from '@/views/CartList/index.vue'
import Checkout from '@/views/Checkout/index.vue'
import Pay from '@/views/Pay/index.vue'

const router = createRouter({
	history: createWebHistory(import.meta.env.BASE_URL),
	routes: [
		// 一级路由
		{
			path: '/', // 首页
			component: Layout,
			// 二级路由
			children: [
				{
					path: '', // 默认首页
					component: Home
				},
				{
					path: 'category/:id', // 一级分类页
					component: Category
				},
				{
					path: 'category/sub/:id', // 二级分类页
					component: SubCategory
				},
				{
					path: 'detail/:id', // 商品详情页
					component: Detail
				},
				{
					path: 'cartList', // 购物车列表页
					component: CartList
				},
				{
					path: 'checkout', // 购物车列表页
					component: Checkout
				},
				{
					path: 'pay', // 支付页
					component: Pay
				},
			]
		},
		{
			path: '/login', // 登录页
			component: Login
		}
	],
	// 路由滚动行为定制：路由切换时页面总是显示在最顶部
	scrollBehavior(){
		return {
			top: 0
		}
	}
})

export default router
